package datastructure_algorithm.stack;

import datastructure_algorithm.linkedlist.LinkedList;

public class LinkedListStack<E> implements Stack<E> {

	private LinkedList<E> list = new LinkedList<>();

	@Override
	public void push(E e) {
		list.addFirst(e);
	}

	@Override
	public E pop() {
		return list.removeFirst();
	}

	@Override
	public E peek() {
		return list.getFirst();
	}

	@Override
	public int getSize() {
		return list.getSize();
	}

	@Override
	public boolean isEmpty() {
		return list.isEmpty();
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("LinkedListStack: top [");
		for (int i = 0; i < list.getSize(); i++) {
			sb.append(list.get(i));
			sb.append(", ");
		}
		sb = sb.delete(sb.length() - 2, sb.length());
		sb.append("]");
		return sb.toString();
	}

}
